To organize routes efficiently using route groups with prefixes and middleware, making code cleaner and easier to manage.
// Define a route group with a prefix and middleware
Route::prefix('admin')
->middleware('auth')
->group(function () {
Route::get('dashboard', [AdminController::class, 'dashboard']);
Route::get('settings', [AdminController::class, 'settings']);
});
Adds the 'admin' prefix to all routes in this group, so they will be like admin/dashboard and admin/settings.Route::prefix('admin'):
Applies the 'auth' middleware to all routes in this group, meaning users must be authenticated to access these routes.->middleware('auth'):
Groups multiple routes together, making it easier to apply common settings like prefixes and middleware.->group(function () { ... }):
You Might Also Like
Keep Data Without Deleting It: Using Laravel Soft Delete
# Step 1: Enable Soft Deletes in Your Model Add SoftDeletes to your model. Let's take an example wit...
Minimize Direct Queries in Blade Views
Avoid executing database queries directly within Blade templates. Instead, fetch data in the control...